#include "Basicclass.h"

/*战斗初始化*/
void Battle::Init(Monster* source, Monster* target) {
    //初始化战场，怪物等
    this->your_monster = source;
    this->enemy_monster = target;
    source->enemy = target;
    target->enemy = source;
}

void Battle::Init(Player* player, Monster* enemy_monster)
{
    this->your_monster = player->use_monster[0];
    this->enemy_monster = enemy_monster;
    player->use_monster[0]->enemy = enemy_monster;
    enemy_monster->enemy = player->use_monster[0];
}

/*战斗开始*/
void Battle::StartBattle()
{
    //战斗开始，场景布置，音乐播放 ,流程控制循环
    while (this->your_monster->isAlive && this->enemy_monster->isAlive) {
        if (this->your_monster->Speed < this->enemy_monster->Speed)
        {
            this->ComputerTurn();
            this->PlayerTurn();
        }
        else
        {
            this->PlayerTurn();
            this->ComputerTurn();
        }

    }
    cout << "战斗结束" << endl;
    if (this->your_monster->isAlive) win = true;
    else win = false;//判断是否胜利
}

/*玩家回合*/
void Battle::PlayerTurn() {
    // 玩家回合逻辑
    cout << "玩家回合" << endl;
    SelectAction();
}

/*计算机回合*/
void Battle::ComputerTurn() {
    cout << "计算机回合" << endl;
    // 1. 初始化随机引擎（推荐 Mersenne Twister）
    std::random_device rd;  // 用于获取真随机种子
    std::mt19937 gen(rd()); // 使用 Mersenne Twister 引擎
    // 2. 定义分布范围（例如生成 0~99 的整数）
    std::uniform_int_distribution<int> dist(0, 3);
    // 3. 生成随机数
    int random_num = dist(gen);
    this->enemy_monster->SkillUse(random_num);

    // 计算机回合逻辑
}

/*怪物行动轮*/
void Battle::SelectAction() {
    cout << "选择行动" << endl;
    cout << "1.战斗" << endl;
    cout << "2.道具" << endl;
    cout << "3.切换宝可梦" << endl;
    cout << "4.逃跑" << endl;
    int action;
    cin >> action;
    switch (action) {
    case 1:
        SkillUse();
        break;
    case 2:
        ItemUse();
        break;
    case 3:
        //切换宝可梦
        ChangeMonster();
        break;
    case 4:
        RunAway();
        break;
    default:
        cout << "无效的选择" << endl;
        break;
    }
}

/*使用技能*/
void Battle::SkillUse() {
    /*技能列表*/
    cout << "技能列表" << endl;
    cout << your_monster->have_skill[0].skill->skill_name << endl;
    cout << your_monster->have_skill[1].skill->skill_name << endl;
    cout << your_monster->have_skill[2].skill->skill_name << endl;
    cout << your_monster->have_skill[3].skill->skill_name << endl;
    int choose;
    cin >> choose;
    your_monster->SkillUse(choose - 1);
    // 使用技能逻辑
}

/*使用道具*/
void Battle::ItemUse() {
    // 使用道具逻辑
}

/*切换宝可梦*/
void Battle::ChangeMonster() {
    cout << "切换宝可梦" << endl;
    cout << "当前宝可梦:" << this->your_monster->name << endl;
    cout << "选择宝可梦" << endl;
    cout << "1." << this->player1->use_monster[0]->name << endl;
    cout << "2." << this->player1->use_monster[1]->name << endl;
    cout << "3." << this->player1->use_monster[2]->name << endl;
    cout << "4." << this->player1->use_monster[3]->name << endl;
    int choose;
    cin >> choose;
    this->your_monster = this->player1->use_monster[choose - 1];
    this->enemy_monster->enemy = this->your_monster;
    this->your_monster->enemy = this->enemy_monster;
    // 切换宝可梦逻辑
}

/*逃跑*/
void Battle::RunAway() {
    this->your_monster->isAlive = false;
    // 逃跑逻辑
}
